function showWinAddFlagField(){
	Ext.QuickTips.init();
	var formInput = Ext.widget({
		id		: 'formInput',
		xtype	: 'form',
		frame	: false,
	    width	: 400,
		height	: 200,
		bodyPadding: 10,
		region 	: 'center',
		defaults: {
				msgTarget   : 'side',
				labelWidth: 75
			},
		items	: [{
					xtype			: 'hidden',
					allowBlank		: false,
					id				: 'id_golfcourse'
				},{
					xtype			: 'textfield',
					allowBlank		: false,
					width			: 300,
					fieldLabel		: 'Golf Course',
					emptyText		: 'F4 to search...',
					id				: 'golfcourse',
					enableKeyEvents : true,
					listeners       : {
						keypress : function(th,e){
								if(e.keyCode == 115){
										showWinGolfCourse();
								}
						}
					}
				},{
					xtype			: 'hidden',
					allowBlank		: false,
					id				: 'id_flag'
				},{
					xtype			: 'textfield',
					readOnly		: true,
					allowBlank		: false,
					width			: 300,
					fieldLabel		: 'Flag',
					emptyText		: 'F4 to search...',
					id				: 'flag',
					enableKeyEvents : true,
					listeners       : {
						keypress : function(th,e){
								if(e.keyCode == 115){
										showWinFlag();
								}
						}
					}
				},{
					xtype		: 'datefield',
					id			: 'period',
					format		: 'd/m/Y',
					fieldLabel	: 'Period',
					allowBlank	: false,
				}],
			buttonAlign: 'center',
			buttons:[
						{
							text: 'Insert',
							handler: function(){
								if(formInput.getForm().isValid()){
									var values = Ext.getCmp('formInput').getValues();
									Ext.Ajax.request({
										url: base_url+'/FlagField/FlagFieldCrud/insert',
										params: values,
										method:'POST',
										success: function(response) {
												var obj = Ext.decode(response.responseText);
												if(obj.feedback[0].code==1){
													Ext.MessageBox.show({
													   title: 'Caution',
													   msg: obj.feedback[0].message,
													   buttons: Ext.MessageBox.OK
												   });
												   winAdd.close(function(){document.body.removeChild(document.getElementById("winAdd"))});
												   strFlagField.load();
												}
												else{
													Ext.MessageBox.show({
													   title: 'Caution',
													   msg: obj.feedback[0].message,
													   buttons: Ext.MessageBox.OK,
													   icon: Ext.MessageBox.ERROR
												   });
												}
										}
									});
								}
							}
							},{
								text	: 'Reset',
								handler: function(){
									Ext.getCmp('FlagField').reset();
									Ext.getCmp('id_company').reset();
									Ext.getCmp('handicap').reset();
									Ext.getCmp('company').reset();
								}
							}
			]
    });
    var winAdd = new Ext.create('widget.window', {
                title	: 'FlagField Setting Input Data',
                closable:true,
                width:400,
                height:200,
                modal:true,
                //border:false,
				id:'winAdd',
                plain:true,
                closeAction: 'close',
                layout: 'border',
				listeners:{
					'close':function(){document.body.removeChild(document.getElementById("winAdd"));}
				},
                items: [formInput]
            });
	winAdd.show();		
}
	//EDIT WINDOW
function showWinEditFlagField(){
	Ext.QuickTips.init();
	var formEdit = Ext.widget({
    id		: 'formEdit',
	xtype	: 'form',
	width	: 400,
    height	: 200,
	bodyPadding: 10,
    region 	: 'center',
    defaults: {
            msgTarget   : 'side',
			labelWidth: 75
        },
	items	: [{
					xtype			: 'hidden',
					allowBlank		: false,
					id				: 'id'
				},{
					xtype			: 'hidden',
					allowBlank		: false,
					id				: 'id_golfcourse'
				},{
					xtype			: 'textfield',
					allowBlank		: false,
					width			: 300,
					fieldLabel		: 'Golf Course',
					emptyText		: 'F4 to search...',
					id				: 'golfcourse',
					enableKeyEvents : true,
					listeners       : {
						keypress : function(th,e){
								if(e.keyCode == 115){
										showWinGolfCourse();
								}
						}
					}
				},{
					xtype			: 'hidden',
					allowBlank		: false,
					id				: 'id_flag'
				},{
					xtype			: 'textfield',
					readOnly		: true,
					allowBlank		: false,
					width			: 300,
					fieldLabel		: 'Flag',
					emptyText		: 'F4 to search...',
					id				: 'flag',
					enableKeyEvents : true,
					listeners       : {
						keypress : function(th,e){
								if(e.keyCode == 115){
										showWinFlag();
								}
						}
					}
				},{
					xtype		: 'datefield',
					id		: 'period',
					fieldLabel	: 'Period',
					allowBlank	: false,
				}],
        buttonAlign: 'center',
        buttons:[
                    {
                        text: 'Save',
                        handler: function(){
							var values = Ext.getCmp('formEdit').getValues();
                            Ext.Ajax.request({
								url: base_url+'/FlagField/FlagFieldCrud/update',
								params: values,
								method:'POST',
								success: function(response) {
										var obj = Ext.decode(response.responseText);
										if(obj.feedback[0].code==1){
											Ext.MessageBox.show({
											   title: 'Caution',
											   msg: obj.feedback[0].message,
											   buttons: Ext.MessageBox.OK
										   });
										   winEdit.close(function(){document.body.removeChild(document.getElementById("winEdit"))});
										   strFlagField.load();
										}
										else{
											Ext.MessageBox.show({
											   title: 'Caution',
											   msg: obj.feedback[0].message,
											   buttons: Ext.MessageBox.OK,
											   icon: Ext.MessageBox.ERROR
										   });
										}
									}
								});

                        }
                        },{
                            text	: 'Reset',
                            handler: function(){
                                rec = gridFlagField.getSelectionModel().getSelection()[0];
								Ext.getCmp('id').setValue(rec.get('ID'));
								Ext.getCmp('FlagField').setValue(rec.get('FlagField'));
								Ext.getCmp('id_company').setValue(rec.get('COMPANY_ID'));
								Ext.getCmp('handicap').setValue(rec.get('HANDICAP'));
								Ext.getCmp('company').setValue(rec.get('COMPANY'));
                            }
                        }
        ]
    });
    var winEdit = new Ext.create('widget.window', {
                title	: 'User Edit Data',
                closable:true,
                width:400,
                height:200,
                modal:true,
                //border:false,
                plain:true,
				closeAction: 'close',
                layout: 'border',
				id:'winEdit',
				listeners:{
					'close':function(){document.body.removeChild(document.getElementById("winEdit"));}
				},
                items: [formEdit]
            });
		winEdit.show();
}
function showWinFlag(){
	Ext.define('mdFlag', {
		extend: 'Ext.data.Model',
		fields: ['ID', 'NAMA']
	});
	var strFlag = new Ext.create('Ext.data.Store', {
		autoLoad : true,
		model: 'mdFlag',
		pageSize: 20,
		proxy: {
			type: 'ajax',
			url: base_url+'/Flag/FlagCrud/GetAllFlag',
			method: 'POST',
			reader: {
					type : 'json',
					root : 'rows',
					totalProperty  : 'results'
				}
		}

	});
	function searchResultQAdd(){
			Ext.getCmp('gridFlag').body.mask('Loading Data... ','x-mask-loading');
			strFlag.proxy.extraParams = { query:Ext.getCmp('srcTxtFlag').getValue()}; //SET STORE EXTRA PARAMS FOR SEND PARAMATER USING AJAX
			strFlag.load(); // LOAD STORE DEFAULT FUNCTION BUT, BASE ON EXTRA PARAMS IN CODE UP THERE  
			strFlag.on("load", function() {
			Ext.getCmp('gridFlag').body.unmask();
		});
	}    
	var bar = {
				xtype           : 'textfield',
				labelSeparator  : '',
				id              : 'srcTxtFlag',
				emptyText		: 'Search...',
				enableKeyEvents : true,
				width           : 200,
				listeners       : {
						keypress : function(th,e){
								if(e.keyCode == 13){
										searchResultQAdd();
								}
						}
				}
		}
	var gridFlag = new Ext.create('Ext.grid.Panel', {
		id:'gridFlag',
		// frame: true, 
		columnLines: true,
		region:'center',
		border: false, 
		store: strFlag, 
		height: '100%',
		width: '100%',
		region:"center",
		forceFit: true,
		columns: [{xtype: 'rownumberer'},
				{
					header: 'Flag',
					dataIndex: 'NAMA',
				}
		 ],
		 dockedItems: [{
			xtype: 'toolbar',
			items: [
						'Search : ',bar
					],
		}],
		bbar: {
			xtype: 'pagingtoolbar',
			pageSize: 20,
			store: strFlag,
			displayInfo: true,
			plugins: new Ext.ux.ProgressBarPager()
		},
		listeners:{
			'itemdblclick': function(dv, record, item, index, e) {
				rec = gridFlag.getSelectionModel().getSelection()[0];
				Ext.getCmp('id_flag').setValue(rec.get('ID'));
				Ext.getCmp('flag').setValue(rec.get('NAMA'));
				winFlag.close();
			}
		}

	});

	var winFlag = new Ext.create('widget.window', {
                title		: 'Flag Search',
				width       : 400,
				autoHeight  : true,
				resizable   : false,
				modal       : true,
				id			:'winFlag',
				listeners:{
					'close':function(){document.body.removeChild(document.getElementById("winFlag"));}
				},
                items: [gridFlag]
            });
	winFlag.show();
}

function showWinGolfCourse(){
	Ext.define('mdGolfCourse', {
		extend: 'Ext.data.Model',
		fields: ['ID', 'NAME', 'ID_TEEBOX', 'NAMA_TEEBOX']
	});
	var strGolfCourse = new Ext.create('Ext.data.Store', {
		autoLoad : true,
		model: 'mdGolfCourse',
		pageSize: 20,
		proxy: {
			type: 'ajax',
			url: base_url+'/GolfCourse/GolfCourseCrud/GetAllGolfCourse',
			method: 'POST',
			reader: {
					type : 'json',
					root : 'rows',
					totalProperty  : 'results'
				}
		}

	});
	function searchResultQAdd(){
			Ext.getCmp('gridGolfCourse').body.mask('Loading Data... ','x-mask-loading');
			strGolfCourse.proxy.extraParams = { query:Ext.getCmp('srcTxtGolfCourse').getValue()}; //SET STORE EXTRA PARAMS FOR SEND PARAMATER USING AJAX
			strGolfCourse.load(); // LOAD STORE DEFAULT FUNCTION BUT, BASE ON EXTRA PARAMS IN CODE UP THERE  
			strGolfCourse.on("load", function() {
			Ext.getCmp('gridGolfCourse').body.unmask();
		});
	}    
	var bar = {
				xtype           : 'textfield',
				labelSeparator  : '',
				id              : 'srcTxtGolfCourse',
				emptyText		: 'Search...',
				enableKeyEvents : true,
				width           : 200,
				listeners       : {
						keypress : function(th,e){
								if(e.keyCode == 13){
										searchResultQAdd();
								}
						}
				}
		}
	var gridGolfCourse = new Ext.create('Ext.grid.Panel', {
		id:'gridGolfCourse',
		// frame: true, 
		columnLines: true,
		region:'center',
		border: false, 
		store: strGolfCourse, 
		height: '100%',
		width: '100%',
		region:"center",
		forceFit: true,
		columns: [{xtype: 'rownumberer'},
				 {
					header: 'Golf Course',
					dataIndex: 'NAME',
				},{
					header: 'Tee Box',
					dataIndex: 'NAMA_TEEBOX',
				}
		 ],
		 dockedItems: [{
			xtype: 'toolbar',
			items: [
						'Search : ',bar
					],
		}],
		bbar: {
			xtype: 'pagingtoolbar',
			pageSize: 20,
			store: strGolfCourse,
			displayInfo: true,
			plugins: new Ext.ux.ProgressBarPager()
		},
		listeners:{
			'itemdblclick': function(dv, record, item, index, e) {
				rec = gridGolfCourse.getSelectionModel().getSelection()[0];
				Ext.getCmp('id_golfcourse').setValue(rec.get('ID'));
				Ext.getCmp('golfcourse').setValue(rec.get('NAME'));
				winGolfCourse.close();
			}
		}

	});
	var winGolfCourse = new Ext.create('widget.window', {
                title		: 'Golf Course Search',
				width       : 400,
				autoHeight  : true,
				resizable   : false,
				modal       : true,
				id			:'winGolfCourse',
				listeners:{
					'close':function(){document.body.removeChild(document.getElementById("winGolfCourse"));}
				},
                items: [gridGolfCourse]
            });
	winGolfCourse.show();
}